<template>
<!-- 必须含有跟便签 -->
  <div>
    {{msgs}}
    {{msg}}
    <br>
    {{aaa}}
    <div>
      <ul>
        <li v-for="(item,index) in list" :key="index">{{item}}</li>
      </ul>
      <div>
        <span v-for="(value,name) in obj" :key="name" :class="{'red':name=='name'}" :style="{'background':background}">
        {{name}} --- {{value}}
        </span>
      </div>
    </div>
    <input type="text" v-model="obj.name" ref="box">
    <button @click="getValue($event)">点我</button><br>
    <button @click="run()">执行父组件的方法</button><br>
    <button @click="getParent()">执行父组件的属性方法</button>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  // props:['msg','aaa','run','hello'],
  props: {
    msg: String,
    aaa: String,
    run: Function,
    hello:Object
  },
  data(){
    return{
      msgs:"ywj",
      list:[1,1,23,43,67],
      obj:{
        name:'ywj',
        age:21
      },
      classAttr:false,
      background:'red'
    }
  },
  methods:{
    getValue(e){
      // 获取dom节点来获取值
      console.log(e)
      console.log(this.$refs.box.value)
      console.log(this.obj.name);
      console.log(123);
    },
    getParent(){
      this.hello.run()
    },
    setValue(val){
      console.log(val);
    }
  },
  mounted(){
    this.$parent.run();
  }

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
.red{
  color: #42b983
}
</style>
